package com.imooc.coupon.controller;

import com.google.common.collect.Maps;
import com.imooc.coupon.constant.CouponChannel;
import com.imooc.coupon.constant.CouponStatus;
import com.imooc.coupon.service.IStreamProducer;
import com.imooc.coupon.vo.CouponMessage;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;

/**
 * 测试处理器
 */
@RestController
@Slf4j
public class TestController {

    @Autowired
    private Map<String, MessageChannel> channelMap;

    @Autowired
    IStreamProducer streamProducer;


    /**
     * 测试流事件发布
     *
     * @return
     */
    @GetMapping("stream/test")
    public boolean streamTest() {

        CouponMessage couponMessage = new CouponMessage();
        couponMessage.setStatus(CouponStatus.USED.getCode());
        couponMessage.setIds(Arrays.asList(14));

        boolean result = streamProducer.sendMessage(CouponChannel.COUPON_MESSAGE_OUTPUT, couponMessage);


        System.out.println(result);
        return result;

    }

}
